<!DOCTYPE HTML>
<html>
  <head>
	<?php echo Yaf_View_Simple::render("header.phtml"); ?>
  </head>
  <body>
	<?php echo Yaf_View_Simple::render("menu.phtml"); ?>
	<div class="container">
	  <div class="content">
        <table class="table table-condensed">
	      <thead>
		    <tr>
              <th>ID</th>
			  <th>Name</th>
			  <th>Create Time</th>
			  <th>审核</th>
			  <th>Setting</th>
		    </tr>
	      </thead>
	      <tbody id="tbody">
		    <?php foreach($member as $value) { ?>
		    <tr>
              <td><?php echo $value['id']; ?></td>
			  <td><?php echo $value['name']; ?></td>
			  <td><?php echo $value['create_time']; ?></td>
			  <td>
                <?php if($value['status'] ==1){ ?>
                <button type="button" class="btn btn-default" data-status="<?php echo $value['status'] ?>" data-id="<?php echo $value['id']; ?>" onclick = "page.status('/admin/member/status/',this)">
                  <span class="glyphicon glyphicon-ok" aria-hidden="true">
                  </span>
                </button>
                <?php }else{ ?>
                <button type="button" class="btn btn-default" data-status="<?php echo $value['status'] ?>" data-id="<?php echo $value['id']; ?>" onclick = "page.status('/admin/member/status/',this)">
                  <span class="glyphicon glyphicon-off" aria-hidden="true">
                  </span>
                </button>
                <?php } ; ?>
              </td>
              <td>
                <div class="btn-group" role="group" aria-label="...">
                  <button type="button" class="btn btn-default">
                    <a href="./edit?id=<?php echo $value['id']; ?>">
                      <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                    </a>
                  </button>
                  <button type="button-remove" class="btn btn-default" onclick ="page.remove(this)" data-value="<?php echo $value['id']; ?>">
                    <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
                  </button>
                </div>                             
              </td>
		    </tr>								
		    <?php } ?>
	      </tbody>
        </table>
     	<div class="pagination" id ="pagination">
		  <ul>
		  </ul>
		</div>
	  </div>
	</div>  
    <!-- Modal -->
    <div class="modal" id="imodal" tabindex="-1" role="dialog" aria-labelledby="modallable">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-body bg-danger">
            <p>Are you sure to remove?</p>
          </div>
          <div class="modal-footer">
            <button type="button" id="close" class="btn btn-primary">Yes</button>
          </div>          
        </div>
      </div>
    </div>        
	<?php echo Yaf_View_Simple::render("footer.phtml"); ?>
    <script type="text/javascript">
     ;(function(){
         var status = function(url,obj){
	         that = $(obj);
	         _this = this;
             var data = {
                 'id' :that.attr('data-id'),
                 'status':parseInt(that.attr('data-status')),
             }
             $.ajax({
                 type:"post",
                 url :url,
                 data:data,
                 success:function(e){
                     if(e.status == 1){
                         if(data.status == 1){
                             console.log(data);
                             var span = that.find('span');
                             span.removeClass();
                             span.addClass('glyphicon glyphicon-off');
                             that.attr({'data-status':0})
                         }else{
                             var span = that.find('span');
                             span.removeClass();
                             span.addClass('glyphicon glyphicon-ok')
                             that.attr({'data-status':1})
                         }
                     }else{
                         return false;
                     }
                 },
                 dataType:'json'
             });
         }
         var remove = function(obj){
             that = $(obj);
             var modal = $('#imodal');
             modal.modal();
             
             modal.find('#close').on('click',function(){
                 var id = that.attr('data-value');
                 var data = {'id':id};
                 var url = '/admin/member/remove';
                 /*                  that.parent().parent().remove();*/
                 /* console.log(that.parent().parent().parent());
                  * modal.modal('hide');*/
                 
                 $.ajax({
                     type:"post",
                     url : url,
                     data: data,
                     success:function(e){
                         if(e.status == 1){
                             that.parent().parent().parent().remove();
                             modal.modal('hide');
                         }else{
                             $(this).find('.modal-body').text(e.msg);
                             return false;
                         }
                     },
                     dataType: 'json',
                 });
             })
             
         }
         return page = {
             status : status,
             remove : remove
         }
     }())
    </script>
  </body>
</html>

